<template>
  <LoadingNodata :loading="loading" :data="dataList" emptyText="暂无评论数据">
    <PersonCommon :showAskStatus="false" :commonRecords="dataList" />
  </LoadingNodata>
</template>
<script setup>
import { onMounted, ref, unref, watch, defineProps, defineEmits } from "vue";
import { myCommit } from "@/service/personalCenter";
import PersonCommon from "@/components/PersonCommon";
import LoadingNodata from "@/components/LoadingNodata";

const props = defineProps({
  page: {
    type: Number,
    default: 1
  },
  pageSize: {
    type: Number,
    default: 10
  }
});

const emit = defineEmits(['update-total', 'change']);

const dataList = ref([]);
const loading = ref(false);
const total = ref(0);

// 监听分页变化
watch(
  () => [props.page, props.pageSize],
  () => {
    fetchData();
  }
);

// 获取评论列表数据
const fetchData = async () => {
  try {
    loading.value = true;
    const resp = await myCommit({
      page: props.page,
      rows: props.pageSize,
    });
    
    if (resp && resp.code === '000000' && resp.data) {
      dataList.value = resp.data.result || [];
      total.value = resp.data.totalCount || 0;
      emit('update-total', total.value);
    } else {
      dataList.value = [];
      total.value = 0;
      emit('update-total', 0);
    }
  } catch (error) {
    console.error('获取评论列表失败:', error);
    dataList.value = [];
    total.value = 0;
    emit('update-total', 0);
  } finally {
    loading.value = false;
  }
};

onMounted(() => {
  fetchData();
});
</script>

<style lang="scss" scoped></style>
